using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.DataAccessProvider;
using DTN.Core;
namespace com.dtn.deals
{
	public class tbl_SupportOnlineManager : Itbl_SupportOnlineManager
	{
		private static Itbl_SupportOnlineManager itbl_SupportOnlineManager = null;
		private tbl_SupportOnlineManager()
		{
		}
		public static Itbl_SupportOnlineManager CreateInstance()
		{
			if (itbl_SupportOnlineManager == null)
			{
				itbl_SupportOnlineManager = new tbl_SupportOnlineManager();
			}
			return itbl_SupportOnlineManager;
		}
		public int Inserttbl_SupportOnline(tbl_SupportOnline tbl_supportonline)
		{
			DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
			int inumOfRowEffect = 0;
			SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
																new SqlParameter("@name", SqlDbType.NVarChar),
																new SqlParameter("@YM", SqlDbType.NVarChar),
																new SqlParameter("@Skype", SqlDbType.NVarChar),
																new SqlParameter("@Phone", SqlDbType.NVarChar),
																new SqlParameter("@cDate", SqlDbType.DateTime),
															};
			parameters[0].Direction = ParameterDirection.Output;
			parameters[1].Value = tbl_supportonline.name;
			parameters[2].Value = tbl_supportonline.YM;
			parameters[3].Value = tbl_supportonline.Skype;
			parameters[4].Value = tbl_supportonline.Phone;
			parameters[5].Value = tbl_supportonline.cDate;
			try
			{
				inumOfRowEffect = dataProvider.ExecuteNonQuery("sp_Inserttbl_SupportOnline", CommandType.StoredProcedure, parameters);
				tbl_supportonline.ID = Convert.ToInt32(parameters[0].Value);
			}
			catch (Exception ex)
			{
				tbl_supportonline.ID = -1;
			}
			return tbl_supportonline.ID;
		}
		public bool Updatetbl_SupportOnline(tbl_SupportOnline tbl_supportonline)
		{
			bool bresult = false;
			DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
			int inumOfRowEffect = 0;
			SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
																new SqlParameter("@name", SqlDbType.NVarChar),
																new SqlParameter("@YM", SqlDbType.NVarChar),
																new SqlParameter("@Skype", SqlDbType.NVarChar),
																new SqlParameter("@Phone", SqlDbType.NVarChar),
																new SqlParameter("@cDate", SqlDbType.DateTime),
															};
			parameters[0].Value = tbl_supportonline.ID;
			parameters[1].Value = tbl_supportonline.name;
			parameters[2].Value = tbl_supportonline.YM;
			parameters[3].Value = tbl_supportonline.Skype;
			parameters[4].Value = tbl_supportonline.Phone;
			parameters[5].Value = tbl_supportonline.cDate;
			try
			{
				inumOfRowEffect = dataProvider.ExecuteNonQuery("sp_Updatetbl_SupportOnline", CommandType.StoredProcedure, parameters);
				bresult = true;
			}
			catch (Exception ex)
			{
				bresult = false;
			}
			return bresult;
		}
		public bool Deletetbl_SupportOnline(int id)
		{
			bool bresult = false;
			DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
			int inumOfRowEffect = 0;
			SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
															};
			parameters[0].Value = id;
			try
			{
				inumOfRowEffect = dataProvider.ExecuteNonQuery("sp_Deletetbl_SupportOnline", CommandType.StoredProcedure, parameters);
				bresult = true;
			}
			catch (Exception ex)
			{
				bresult = false;
			}
			return bresult;
		}
		public tbl_SupportOnline Selecttbl_SupportOnlineByID(int id)
		{
			IDataReader dr;
			tbl_SupportOnline tbl_supportonline = new tbl_SupportOnline();
			DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
			SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@ID", SqlDbType.Int),
															};
			parameters[0].Value = id;
			try
			{
				dr = dataProvider.ExecuteReader("sp_Selecttbl_SupportOnline", CommandType.StoredProcedure, parameters);
				while(dr.Read())
				{
					tbl_supportonline.ID = Convert.ToInt32(dr["ID"].ToString());
					tbl_supportonline.name = (dr["name"].ToString());
					tbl_supportonline.YM = (dr["YM"].ToString());
					tbl_supportonline.Skype = (dr["Skype"].ToString());
					tbl_supportonline.Phone = (dr["Phone"].ToString());
					tbl_supportonline.cDate = Convert.ToDateTime(dr["cDate"].ToString());
				}

			}
			catch (Exception ex)
			{
				return null;
			}
			return tbl_supportonline;
		}
		public DataTable Selecttbl_SupportOnlinesDynamic(string Where, string Order)
		{
			DataSet ds = new DataSet();
			DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
			SqlParameter[] parameters = new SqlParameter[]{
																new SqlParameter("@WhereCondition", SqlDbType.NVarChar,500),
																new SqlParameter("@OrderByExpression", SqlDbType.NVarChar,250),
															};
			parameters[0].Value = Where;
			parameters[1].Value = Order;
			try
			{
				ds = dataProvider.ExecuteDataSet("sp_Selecttbl_SupportOnlinesDynamic", CommandType.StoredProcedure, parameters);
			}
			catch (Exception ex)
			{
				return null;
			}
			return ds.Tables["Table"];
		}
        public DataTable Selecttbl_SupportDynamicWithPage(int StartIndex, int MaxRecords, string Where) 
        {
            DataSet ds = new DataSet();
            DataProviderBaseClass dataProvider = DataProvider.GetDataProvider(EnumDataProviderType.SqlClient, DataHelper.GetConnectionString());
            SqlParameter[] parrams = { new SqlParameter("@Startindex",SqlDbType.Int ){Value = StartIndex },
                                         new SqlParameter("@Maxrecords",SqlDbType.Int ){Value = MaxRecords  },
                                         new SqlParameter("@WhereCondition",SqlDbType.NVarChar,500 ){Value = Where  }
                                     };
            try
            {
                ds = dataProvider.ExecuteDataSet("sp_Selecttbl_SupportWithPagesDynamic", CommandType.StoredProcedure, parrams);
            }
            catch (Exception ex)
            {
                return null;
            }
            return ds.Tables["Table"];
        }
	}
}
